package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.ConceptualCarDAO;
import edu.byu.intex2.data.dao.PhysicalCarDAO;
import edu.byu.intex2.data.dao.WarrantyDAO;
import java.util.List;

/**
 * @author Jason Whiting
 */
public class PhysicalCar extends BusinessObject
{

    private String vin;
    private double price;
    private String color;
    private List<Warranty> warranties;
    /** Conceptual Car */
    private String conceptualCarId;
    private ConceptualCar conceptualCar = null;

//    private Lot lot;
    /**
     * Creates a new instance of BusinessObject
     * @param id
     */
    public PhysicalCar(String id)
    {
        super(id);
    }//constructor

    /** @return the vin */
    public String getVin()
    {
        return vin;
    }

    //Quick Access Method
    public void save() throws DataException
    {
        try
        {
            PhysicalCarDAO.getInstance().save(this);
        } catch (DataException e)
        {
            e.printStackTrace();
        }
    }

    /** @param vin the vin to set     */
    public void setVin(String vin)
    {
        this.vin = vin;
        setDirty();
    }

    /** @return the price     */
    public double getPrice()
    {
        return price;
    }

    /** @param price the price to set     */
    public void setPrice(double price)
    {
        this.price = price;
        setDirty();
    }

    /** @return the color     */
    public String getColor()
    {
        return color;
    }

    /** @param color the color to set    */
    public void setColor(String color)
    {
        this.color = color;
        setDirty();
    }

    /**
     * @return the warranties
     */
    public List<Warranty> getWarranties()
    {
//        if (warranties == null){
        try
        {
            warranties = WarrantyDAO.getInstance().getByPhysicalCar(id);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
//        }
        return warranties;
    }

    /**
     * @param warranties the warranties to set
     */
    public void setWarranties(List<Warranty> warranties)
    {
        this.warranties = warranties;
    }

    /**
     * @return the conceptualCarId
     */
    public String getConceptualCarId()
    {
        return conceptualCarId;
    }

    /**
     * @param conceptualCarId the conceptualCarId to set
     */
    public void setConceptualCarId(String conceptualCarId)
    {
        this.conceptualCarId = conceptualCarId;
        this.setDirty();
    }

    /**
     * @return the conceptualCar
     */
    public ConceptualCar getConceptualCar()
    {
        if (conceptualCar == null)
        {
            try
            {
                conceptualCar = ConceptualCarDAO.getInstance().read(conceptualCarId);
            } catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        return conceptualCar;
    }

    /**
     * @param conceptualCar the conceptualCar to set
     */
    public void setConceptualCar(ConceptualCar conceptualCar)
    {
        this.conceptualCar = conceptualCar;
        this.setDirty();
    }

    @Override
    public String toString()
    {
        return getConceptualCar().getMake() + ", " + getConceptualCar().getModel() + ", " + getConceptualCar().getYear();
    }
}
